home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stut_src / pagecran.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  42KB  |  1,822 lines

  1. /*
  2.  * pagecran.c
  3.  *
  4.  * Purpose:
  5.  * --------
  6.  * Cr‚ation des pages ‚cran
  7.  *
  8.  * History:
  9.  * --------
  10.  * 18.06.1994: fplanque: Created
  11.  */
  12.  
  13.  
  14.      #include "!OPTIONS.H"                /* Options de compilation */         
  15.     #define    THIS_FILE    "PAGECRAN.C v1.00 - 03.95"
  16.           
  17.  
  18. /*
  19.  * System headers:
  20.  */
  21.     #include    <stdio.h>
  22.     #include    <string.h>   
  23.     #include    <stdlib.h> 
  24.     #include <time.h>
  25.     #include <errno.h>
  26.  
  27. /*
  28.  * Custom headers:
  29.  */
  30.     #include "SPEC_PU.H"
  31.     #include "S_MALLOC.H"
  32.     #include "DEBUG_PU.H"
  33.     #include "PROGR_PU.H"
  34.     #include "DATPG_PU.H"
  35.     #include "DTDIR_PU.H"
  36.     #include "DESK_PU.H"
  37.     #include "MAIN_PU.H"
  38.     #include "OBJCT_PU.H"
  39.     #include "PGECR_PU.H"
  40.     #include "RAMSL_PU.H"
  41.     #include "RTERR_PU.H"
  42.     #include "SPEC_PU.H"
  43.     #include    "TERM_PU.H"    
  44.     #include    "MINITEL.H"    
  45.     #include    "TEXT_PU.H"
  46.     #include "WIN_PU.H"
  47.  
  48. /*
  49.  * 03.08.94: n_1stCode est maintenant un int
  50.  */
  51. typedef
  52.     struct
  53.     {
  54.         char    *    pS_inst;
  55.         int        n_1stCode;
  56.         char        c_procIdx;
  57.         char        c_GraphStop;
  58.     }
  59.     COMPILE_CODE;
  60.  
  61. typedef
  62.     struct
  63.     {
  64.         char    *    psz_Var;
  65.         char    *    psz_Val;
  66.     }
  67.     VARIABLE;
  68.  
  69. typedef
  70.     struct    
  71.     {
  72.         char        c_code;
  73.         char    *    psz_instruct;
  74.     }
  75.     DECOMPILE_ESCAPE;
  76.  
  77.     enum
  78.     { 
  79.         CODE_NONE,
  80.         CODE_INK,
  81.         CODE_PAPER,
  82.         CODE_LINE0,
  83.         CODE_TEXT,
  84.         CODE_POS,
  85.         CODE_LOCATE,
  86.         CODE_REP,
  87.         CODE_CODE,
  88.         CODE_FLASH,
  89.         CODE_INVERSE,
  90.         CODE_LINE,
  91.         CODE_SIZE,
  92.         CODE_SCROLL,
  93.         CODE_SGCHAR
  94.     };
  95.  
  96. enum {
  97.     STATUS_ERR_FILEEND = -1000, 
  98.     STATUS_ERR_LINEEND,
  99.     STATUS_ERR_TOOLONG,
  100.     STATUS_ERR_NOTOKEN,
  101.     STATUS_ERR_UNKNOWN,
  102.     STATUS_ERR_OUTOFRANGE,
  103.     
  104.     STATUS_PROGRESS,
  105.     STATUS_INSTRUCTOK };
  106.  
  107. /*
  108.  * S‚parateur d'arguments:
  109.  */
  110. #define    ARGUMENT_SPERATOR 0xFF
  111.     char    * psz_ArgumentSeparator = "\xFF";
  112.  
  113. /*
  114.  * ------------------------ PROTOTYPES -------------------------
  115.  */
  116.  
  117. /*
  118.  * EXTernal prototypes:
  119.  */
  120.     /*
  121.      * Accents:
  122.      */
  123.     extern    char    *convert_Asc2Vdt(         /* Out: Ptr sur tampon de caractŠres ‚quivalents */
  124.                             char    c_ascii );        /* In:  caractŠre … traduire */
  125.  
  126.     
  127. /*
  128.  * PRIVate INTernal prototypes:
  129.  */
  130.     static    DATAPAGE *    add_datapage(
  131.                                     DATATYPE        DataType,        /* In: Grp de donn‚es ds lequel on cr‚e */
  132.                                     const char*    psz_DefName );    /* In: Nom par d‚faut */
  133.     static    void decomp_vdt2text(
  134.                                 DATABLOCK    *    pDataBlock,
  135.                                 const    char    *    cpsz_name,            /* In: Nom de la page qu'on d‚compile */
  136.                                 const char    *    cpsz_NomText,        /* In: Nom du fichier destination */
  137.                                 TEXTINFO        *    pTextInfo );
  138.     static    size_t    compile_text2vdt(                        /* Out: Taille de la page compil‚e */
  139.                                 TEXTINFO     * pTextInfo,        /* In:  Ptr sur texte source */
  140.                                 const char  * cpBsz_Nom,        /* In:  Nom de la page … afficher ds progress */
  141.                                 char     * *    ppm_OutputBuf );    /* Out: Ptr sur buffer contenant le code compil‚ */
  142.     static    BOOL    translate_inst2code( 
  143.                                 char    *    pS_inst,
  144.                                 char    *    pS_arg1,        /* In: Premier paramŠtre */
  145.                                 char    *    pS_arg2 );    /* In: DeuxiŠme paramŠtre */
  146.     static    int    filter_memcpy( 
  147.                             char    *    pm_dest,
  148.                             char    *    pm_source,
  149.                             int        n_length );
  150.  
  151.  
  152.  
  153. /*
  154.  * ------------------------ VARIABLES -------------------------
  155.  */
  156.     
  157. /*
  158.  * External variables: 
  159.  */
  160.     /* 
  161.      * G‚n‚ral: 
  162.      */
  163.     extern    WIPARAMS    *G_wi_list_adr;            /* Adresse de l'arbre de paramŠtres */
  164.     extern    char        *G_tmp_buffer;                /* Peut contenir un texte long de 511 signes + '\0' */
  165.     extern    char        *G_2nd_buffer;                /* 2Šme buffer */
  166.     extern    char        *G_empty_string;            /* Chaine vide */
  167.     /* 
  168.      * Serial: 
  169.      */
  170.     extern    int    G_term_dev;            /* Port utilis‚ par icone terminal */
  171.  
  172.  
  173. /*
  174.  * Private variables: 
  175.  */
  176.     /*
  177.      * Constantes:
  178.      */
  179.     VARIABLE        M_Constantes[]=
  180.                         {
  181.                             "ON"        ,    "1",
  182.                             "OFF"        ,    "0",
  183.                             "NORMAL"    ,    "0",
  184.                             "HIGH"    ,    "1",
  185.                             "WIDE"    ,    "2",
  186.                             "DOUBLE"    ,    "3",
  187.                             NULL        ,    NULL
  188.                         };
  189.     int    M_nbConstantes;        /* Nbre de constantes: initialis‚ dans init_PagesEcran */
  190.     /* 
  191.      * Codes Minitel pour COMPILATION:
  192.      * aussi utilis‚ pour DECOMPILATION en ce qui concerne
  193.      * les insts cod‚es sur 1 seul octet
  194.      */
  195.     COMPILE_CODE    M_TCC_minitel[]=
  196.         {
  197.             "bell"        ,    BEL        ,    0,                    0,
  198.             "can"            ,    CAN        ,    0,                    0,
  199.             "cls"            ,    FF            ,    0,                    1,
  200.             "code"        ,    NIL_1        ,    CODE_CODE,        0,
  201.             "cr"            ,    CR            ,    0,                    0,
  202.             "csroff"        ,    CSR_OFF    ,    0,                    0,
  203.             "csron"        ,    CSR_ON    ,    0,                    0,
  204.             "down"        ,    LF            ,    0,                    0,
  205.             "flash"        ,    ESC        ,    CODE_FLASH,        0,
  206.             "graphmode"    ,    SO            ,    0,                    2,
  207.             "home"        ,    HOME        ,    0,                    1,
  208.             "ink"            ,    ESC        ,    CODE_INK,        0,
  209.             "inverse"    ,    ESC        ,    CODE_INVERSE,    0,
  210.             "left"        ,    BS            ,    0,                    0,
  211.             "line"        ,    ESC        ,     CODE_LINE,        0,
  212.             "line0"        ,    US            ,    CODE_LINE0,        1,
  213.             "loc"            ,    US            ,    CODE_LOCATE,    1,
  214.             "nul"            ,    NUL        ,    0,                    0,
  215.             "paper"        ,    ESC        ,    CODE_PAPER,        0,
  216.             "pos"            ,    US            ,    CODE_POS,        1,
  217.             "repeat"        ,    REP        ,    CODE_REP,        0,
  218.             "right"        ,    HT            ,    0,                    0,
  219.             "scroll"        ,    ESC        ,    CODE_SCROLL,    0,
  220.             "size"        ,    ESC        ,    CODE_SIZE,        0,
  221.             "text"        ,    NIL_1        ,    CODE_TEXT,        0,
  222.             "textmode"    ,    SI            ,    0,                    1,
  223.             "up"            ,    VT            ,    0,                    0,
  224.             "Graph"        ,    NIL_1        ,    CODE_SGCHAR,    0,
  225.             NULL            ,    0            ,    0,                    0
  226.         };
  227.     int    M_nbCodesMinitel;        /* Nbre d'instructions: initialis‚ dans init_PagesEcran */
  228.     /*
  229.      * S‚quences escape pour DECOMPILATION:
  230.      */
  231.     DECOMPILE_ESCAPE M_TDEscapes_mntl[]=
  232.         {
  233.             MNTL_ENOIR,            "ink(0)",
  234.             MNTL_EROUGE,        "ink(2)",
  235.             MNTL_EVERT,            "ink(4)",
  236.             MNTL_EJAUNE,        "ink(6)",
  237.             MNTL_EBLEU,            "ink(1)",
  238.             MNTL_EMAGENTA,        "ink(3)",
  239.             MNTL_ECYAN,            "ink(5)",
  240.             MNTL_EBLANC,        "ink(7)",
  241.  
  242.             MNTL_FLASH_ON,        "flash(ON)",
  243.             MNTL_FLASH_OFF,    "flash(OFF)",
  244.             
  245.             MNTL_SIZE_NORM,    "size(NORMAL)",
  246.             MNTL_SIZE_HIGH,    "size(HIGH)",
  247.             MNTL_SIZE_WIDE,    "size(WIDE)",
  248.             MNTL_SIZE_DOUBLE,    "size(DOUBLE)",
  249.         
  250.             MNTL_ENOIR,            "paper(0)",
  251.             MNTL_FROUGE,        "paper(2)",
  252.             MNTL_FVERT,            "paper(4)",
  253.             MNTL_FJAUNE,        "paper(6)",
  254.             MNTL_FBLEU,            "paper(1)",
  255.             MNTL_FMAGENTA,        "paper(3)",
  256.             MNTL_FCYAN,            "paper(5)",
  257.             MNTL_FBLANC,        "paper(7)",
  258.             
  259.             MNTL_LINE_OFF,        "line(OFF)",
  260.             MNTL_LINE_ON,        "line(ON)",
  261.             
  262.             MNTL_INVERSE_OFF,    "inverse(OFF)",
  263.             MNTL_INVERSE_ON,    "inverse(ON)",
  264.             
  265.             '\0',                    NULL
  266.         };
  267.     int    M_nbEscapes;        /* Nbre de s‚quences ds tableau ci dessus */
  268.     /*
  269.      * Codes couleur:
  270.      * Conversion entre l'ordre d'intensit‚ vers l'ordre vid‚otex
  271.      */
  272.     int    M_CouleursVdt[ 8 ] = { 0, 4, 1, 5, 2, 6, 3, 7 };
  273.     /*
  274.      * Messages d'erreur:
  275.      */
  276.     char    *    M_CompilerError[] =
  277.     {
  278.         /*    STATUS_ERR_FILEEND */        "Fin de fichier pr‚matur‚e: instruction tronqu‚e",
  279.         /* STATUS_ERR_LINEEND */        "Fin de ligne dans une chaŒne texte",
  280.         /*    STATUS_ERR_TOOLONG */        "Instruction trop longue: compilation impossible",
  281.         /* STATUS_ERR_NOTOKEN */        "Token introuvable!",
  282.         /* STATUS_ERR_UNKNOWN */        "Instruction non reconnue",
  283.         /* STATUS_ERR_OUTOFRANGE */    "ParamŠtre hors limites"
  284.     };
  285.     /*
  286.      * Buffer temporaire contenant l'instruction en cours de compilation:
  287.      */
  288.     char         *    M_p_InstrBuf;    
  289. #define    INSTR_BUFFER_SIZE        (TMP_BUFFER_SIZE -1 -10)        /* 10 est une marge de s‚curit‚ pour l'expansion des constantes */
  290.  
  291. /*
  292.  * ------------------------ FUNCTIONS -------------------------
  293.  */
  294.  
  295.  
  296. /*
  297.  * init_PagesEcran(-)
  298.  *
  299.  * Purpose:
  300.  * --------
  301.  * Initialisation n‚cessaires … l'utilisation de ce module
  302.  *
  303.  * History:
  304.  * --------
  305.  * 31.07.94: fplanque: created
  306.  */
  307. void    init_PagesEcran( void )
  308. {
  309.  
  310.     /*
  311.      * Le buffer de stockage commence un octet aprŠs le d‚but du tmp buffer 
  312.      */ 
  313.     M_p_InstrBuf = &G_tmp_buffer[1];
  314.     
  315.     
  316.     /*
  317.      * Cherche combien il y a de constantes:
  318.      */
  319.     M_nbConstantes = 0;
  320.     
  321.     while( M_Constantes[ M_nbConstantes ] .psz_Var != NULL )
  322.     {    /*
  323.          * Une instruction de plus:
  324.          */
  325.         M_nbConstantes++;
  326.     }
  327.  
  328.     /*
  329.      * Cherche combien il y a d'instructions videotex pour COMPILATION:
  330.      */
  331.     M_nbCodesMinitel = 0;
  332.     
  333.     while( M_TCC_minitel[ M_nbCodesMinitel ] .pS_inst != NULL )
  334.     {    /*
  335.          * Une instruction de plus:
  336.          */
  337.         M_nbCodesMinitel++;
  338.     }
  339.  
  340.     /*
  341.      * Cherche combien il y a de s‚quences ESC pour DECOMPILATION:
  342.      */
  343.     M_nbEscapes = 0;
  344.     
  345.     while( M_TDEscapes_mntl[ M_nbEscapes ] .c_code != '\0' )
  346.     {    /*
  347.          * Une s‚quence ESC de plus:
  348.          */
  349.         M_nbEscapes++;
  350.     }
  351.  
  352. }
  353.  
  354.  
  355.  
  356.  
  357. /*
  358.  * decompile_page(-)
  359.  *
  360.  * Purpose:
  361.  * --------
  362.  * D‚compile une page vid‚otex
  363.  *
  364.  * Suggest:
  365.  * --------
  366.  * Lorsqu'on entre dans une s‚quence sp‚ciale, il faut v‚rifier
  367.  * qu'il reste assez de caractŠres pour terminer ladite s‚quence
  368.  *
  369.  * History:
  370.  * --------
  371.  * 31.08.94: fplanque: Created
  372.  * 02.09.94: Prend param GRECT
  373.  * 13.11.94: extension ".SV" pour fichier g‚n‚r‚
  374.  */
  375. void    decompile_page( GRECT * pGRect_start )    /* In: d‚but effet graphique */
  376. {
  377.     DATAPAGE        *    pDataPage_srce;
  378.     TEXTINFO     *    pTextInfo;
  379.     size_t            size;
  380.     char            *    pBuf;
  381.     DATAPAGE        *    pDataPage_dest;    
  382.     DATABLOCK    *    pDataBlock;
  383.     char                Bsz_NomTexte[13];        /* Contient nom du texte cr‚‚ */
  384.         
  385.     FAKE_USE( pGRect_start );
  386.         
  387.     if(   G_selection_adr == NULL
  388.         || G_selection_adr -> class != CLASS_DIR )
  389.     {    /*
  390.          * Si on a pas s‚lectionn‚ d'objet dans un directory:
  391.          */
  392.         ping();
  393.         return;
  394.     }
  395.     
  396.     pDataPage_srce = page_adr_byicno( G_selection_adr -> datadir, G_selection_adr -> selected_icon );
  397.  
  398.     if( pDataPage_srce == NULL || pDataPage_srce -> DataType != DTYP_PAGES )
  399.     {    /*
  400.          * Si on a pas s‚lectionn‚ une page ‚cran:
  401.          */
  402.         return;
  403.     }
  404.  
  405.     /*
  406.      * Cr‚e nom page destination:
  407.      */
  408.     strcpy( Bsz_NomTexte, pDataPage_srce -> nom );
  409.     replace_extension( Bsz_NomTexte, ".SV" );
  410.  
  411.     /*
  412.      * Cr‚e un texte vide:
  413.      */
  414.     pTextInfo = create_TextInfo();
  415.  
  416.     /*
  417.      * D‚compilation:
  418.      */
  419.     decomp_vdt2text( 
  420.             pDataPage_srce -> data.dataBlock, 
  421.             pDataPage_srce -> nom, Bsz_NomTexte, pTextInfo );
  422.  
  423.     /*
  424.      * PROVISOIRE:
  425.      * compactage en bloc:
  426.      */
  427.     size = compact_text(    pTextInfo -> firstline -> next, 
  428.                                             FMTMODE_NEARBINARY, &pBuf );
  429.  
  430.     free_formatext( pTextInfo );
  431.  
  432.     
  433.     /*
  434.      * Sauve ds datapage destination:
  435.      */
  436.     pDataPage_dest = add_datapage( DTYP_TEXTS, Bsz_NomTexte );
  437.  
  438.     /*
  439.      * Cr‚e un datablock contenant le code la page compil‚e:
  440.      */
  441.     pDataBlock    = create_stdDataBlock();
  442.     pDataBlock -> p_block    = pBuf;
  443.     pDataBlock -> ul_length = size;
  444.     
  445.     /*
  446.      * Assigne le code compil‚ … la nouvelle page:
  447.      */
  448.     pDataPage_dest -> data.dataBlock = pDataBlock;
  449.          
  450. }
  451.  
  452.  
  453.  
  454. /*
  455.  * decomp_vdt2text(-)
  456.  *
  457.  * Purpose:
  458.  * --------
  459.  * D‚compile une page vid‚otex
  460.  *
  461.  * Algorythm:
  462.  * ----------  
  463.  * Ajoute … la fin du texte indiqu‚ par TEXTINFO pass‚ en param
  464.  *
  465.  * Suggest:
  466.  * --------
  467.  * Lorsqu'on entre dans une s‚quence sp‚ciale, il faut v‚rifier
  468.  * qu'il reste assez de caractŠres pour terminer la dite s‚quence
  469.  *
  470.  * History:
  471.  * --------
  472.  * 31.08.94: fplanque: Created
  473.  * 08.01.95: utilise loc() plutot que pos()
  474.  */
  475. void decomp_vdt2text(
  476.             DATABLOCK    *    pDataBlock,
  477.             const    char    *    cpsz_name,        /* In: Nom de la page qu'on d‚compile */
  478.             const char    *    cpsz_NomText,    /* IN: Nom du fichier destination */
  479.             TEXTINFO        *    pTextInfo )
  480. {
  481.     char     *    piBlock    = pDataBlock -> p_block;
  482.     char        c_code;
  483.     char     *    psz_Instrcution;
  484.     size_t    s_InstLen;
  485.     char     *    psz_newline;
  486.     ULONG        ul_pos;
  487.     BOOL        b_Graphmode = FALSE0;
  488.     time_t    current_time;
  489.     /*
  490.      * Ligne courante dans texte destination:
  491.      */
  492.     TEXTLINE    *    pTextLine = pTextInfo -> lastline;
  493.     
  494.     /*
  495.      * Affiche progress 
  496.      */
  497.     long    l_BlkSize = start_progress( " D‚compilation Page Ecran: ", 
  498.                                                     cpsz_NomText, pDataBlock -> ul_length, 5, FALSE0 );
  499.     long    l_DoneSize = 0;        /* Pour l'instant on a rien compil‚ */
  500.  
  501.     /*
  502.      * Cr‚e header de texte:
  503.      */
  504.     sprintf( M_p_InstrBuf, "// D‚compilation du fichier %s", cpsz_name );
  505.     psz_newline = STRDUP( M_p_InstrBuf );
  506.     pTextLine = insert_line( pTextLine, psz_newline, NIL_1, pTextInfo );
  507.  
  508.     current_time = time( NULL );
  509.     sprintf( M_p_InstrBuf, "// %s", ctime( ¤t_time ) );
  510.     M_p_InstrBuf[27] = '\0';
  511.     psz_newline = STRDUP( M_p_InstrBuf );
  512.     pTextLine = insert_line( pTextLine, psz_newline, NIL_1, pTextInfo );
  513.  
  514.     /*
  515.      * Parcourt la page:
  516.      */
  517.     for( ul_pos = 0; ul_pos < (pDataBlock -> ul_length); ul_pos++, piBlock++ )
  518.     {
  519.         /*
  520.          * Instruction qui vient d'etre d‚cod‚e:
  521.          */
  522.         psz_Instrcution = NULL;
  523.         
  524.         /*
  525.          * Code en cours:
  526.          */
  527.         c_code = *piBlock;
  528.  
  529.         switch( c_code )
  530.         {
  531.             case    REP:
  532.                 /* 
  533.                  * Il s'agit d'une r‚p‚tition de caractŠres
  534.                  */
  535.                 sprintf( M_p_InstrBuf, "repeat(%d)", (int)piBlock[1]-0x40 );
  536.                 psz_Instrcution = M_p_InstrBuf;
  537.  
  538.                 /*
  539.                  * On avance de 2 caractŠres:
  540.                  */                 
  541.                 ul_pos++;
  542.                 piBlock++;
  543.                 break;
  544.  
  545.  
  546.             case    ESC:
  547.             {
  548.                 int    c_NextCode = piBlock[1];
  549.                 int    n_index;
  550.                 
  551.                 for( n_index=0; n_index < M_nbEscapes; n_index++ )
  552.                 {    /*
  553.                      * Cherche s‚quence esc ds tableau:
  554.                      */
  555.                     if( M_TDEscapes_mntl[ n_index ] .c_code == c_NextCode )
  556.                     {    /*
  557.                          * On a trouv‚:
  558.                          */
  559.                         psz_Instrcution = M_TDEscapes_mntl[ n_index ] .psz_instruct;
  560.                             
  561.                         /*
  562.                          * OK, on avance sur le prochain car:
  563.                          */
  564.                         ul_pos++;
  565.                         piBlock++;
  566.                         break;
  567.                     }
  568.                 }
  569.             }    
  570.                 break;
  571.  
  572.  
  573.             case    US:
  574.                 /* 
  575.                  * Il s'agit d'un POS/LOCATE/LINE0
  576.                  */
  577.                 sprintf( M_p_InstrBuf, "loc(%d,%d)", (int)piBlock[2]-0x40, (int)piBlock[1]-0x40 );
  578.                 psz_Instrcution = M_p_InstrBuf;
  579.  
  580.                 /*
  581.                  * On est plus en Graphmode:
  582.                  */
  583.                 b_Graphmode = FALSE0;
  584.  
  585.                 /*
  586.                  * On avance de 2 caractŠres:
  587.                  */                 
  588.                 ul_pos+=2;
  589.                 piBlock+=2;
  590.                 break;
  591.                             
  592.             default:
  593.                 if( ! b_Graphmode && c_code >= ' ' && c_code < MNTL_DEL )
  594.                 {    /*
  595.                      * Il s'agit de texte normal:
  596.                      */
  597.                     int    n_InstrLen    = 7;        /* On a d‚j… 7 cars ds buf d'instrcution, voir ligne suivante: */
  598.                     
  599.                     sprintf( M_p_InstrBuf, "text(\"%c", c_code );
  600.                     
  601.                     /*
  602.                      * On continue d'ajouter dans le buffer
  603.                      * tant qu'on a des codes apropri‚s:
  604.                      *
  605.                      * Tant qu'on est avant la fin:
  606.                      */
  607.                     while( ul_pos < (pDataBlock -> ul_length)-1 )
  608.                     {
  609.                         /*
  610.                          * Prochain car:
  611.                          */ 
  612.                         c_code = *(piBlock+1);
  613.         
  614.                         if( c_code < ' ' || c_code >= MNTL_DEL )
  615.                         {    /*
  616.                              * Si code hors intervale texte:
  617.                              */
  618.                             break;    /* On termine l'instruction text */
  619.                         }
  620.                         
  621.                         /*
  622.                          * OK, on avance sur le prochain car:
  623.                          */
  624.                         ul_pos++;
  625.                         piBlock++;
  626.         
  627.                         /*
  628.                          * Ajoute code au texte:
  629.                          */
  630.                         M_p_InstrBuf[ n_InstrLen++ ] = c_code;
  631.                         
  632.                         if( n_InstrLen >= INSTR_BUFFER_SIZE-2 )
  633.                         {    /*
  634.                              * Si on a atteint la longueur maximale:
  635.                              * (-2 pour la fin de l'inst:  ")   )
  636.                              */
  637.                             break;
  638.                         }
  639.         
  640.                     }
  641.                     
  642.                     /*
  643.                      * Fin de l'instruction text:
  644.                      */
  645.                     M_p_InstrBuf[ n_InstrLen++ ] = '"';
  646.                     M_p_InstrBuf[ n_InstrLen++ ] = ')';
  647.                     M_p_InstrBuf[ n_InstrLen++ ] = '\0' ;    
  648.  
  649.  
  650.                     psz_Instrcution = M_p_InstrBuf;
  651.                 }
  652.                 else if( b_Graphmode && c_code >= ' ' && c_code <= MNTL_DEL )
  653.                 {    /*
  654.                      * CaractŠre graphique:
  655.                      * Macro de g‚n‚ration d'un caractŠre semi-graphique:
  656.                      * D‚codage selon format:
  657.                      *    positions    0 3        bits                0 1
  658.                      *    dans            1 4        dans                2 3
  659.                      *    source        2 5        destination        4 6
  660.                      */
  661.                     char *pisz = M_p_InstrBuf + 6;
  662.                     
  663.                     strcpy( M_p_InstrBuf, "Graph(" );
  664.                     
  665.                     *(pisz++) = ( c_code & 0x01 ) ? '*' : '-';
  666.                     *(pisz++) = ( c_code & 0x04 ) ? '*' : '-';
  667.                     *(pisz++) = ( c_code & 0x10 ) ? '*' : '-';
  668.                     *(pisz++) = ( c_code & 0x02 ) ? '*' : '-';
  669.                     *(pisz++) = ( c_code & 0x08 ) ? '*' : '-';
  670.                     *(pisz++) = ( c_code & 0x40 ) ? '*' : '-';
  671.                     
  672.                     *(pisz++) = ')';
  673.                     *(pisz) = '\0';
  674.  
  675.  
  676.                     psz_Instrcution = M_p_InstrBuf;
  677.                 }
  678.                 else
  679.                 {    /* 
  680.                     * On a affaire … des codes non imprimables:
  681.                     */
  682.                     int    n_index;
  683.                     
  684.                     for( n_index=0; n_index < M_nbCodesMinitel; n_index++ )
  685.                     {    /*
  686.                          * Cherche s‚quence esc ds tableau:
  687.                          */
  688.                         if( M_TCC_minitel[ n_index ] .c_procIdx == 0
  689.                             && M_TCC_minitel[ n_index ] .n_1stCode == c_code )
  690.                         {    /*
  691.                              * On a trouv‚:
  692.                              */
  693.                             char        c_GraphStop = M_TCC_minitel[ n_index ] .c_GraphStop;
  694.  
  695.                             psz_Instrcution = M_TCC_minitel[ n_index ] .pS_inst;
  696.                                 
  697.                             /*
  698.                              * V‚rifie si on change de Graph/Text-Mode:
  699.                              */
  700.                             if( c_GraphStop == 1 )
  701.                             {
  702.                                 b_Graphmode = FALSE0;
  703.                             }
  704.                             else if( c_GraphStop == 2 )
  705.                             {
  706.                                 b_Graphmode    = TRUE_1;
  707.                             }
  708.  
  709.                             break;
  710.                         }
  711.                     }
  712.                 }
  713.             }
  714.                 
  715.         /*
  716.          * V‚rifie si on a pu d‚coder une instruction (‚volu‚e):
  717.          */
  718.         if( psz_Instrcution == NULL )
  719.         {    /*
  720.              * Code ne peut etre d‚cod‚:
  721.              */
  722.             sprintf( M_p_InstrBuf, "code(%d)", (int)c_code );
  723.             psz_Instrcution = M_p_InstrBuf;
  724.         }    
  725.  
  726.         /*
  727.          * Cr‚e la ligne a ins‚rer:
  728.          * +2 pour ; et \0
  729.          */
  730.         s_InstLen = strlen( psz_Instrcution );
  731.  
  732.         psz_newline = (char*) MALLOC( s_InstLen +2 );
  733.         memcpy( psz_newline, psz_Instrcution, s_InstLen );
  734.  
  735.         psz_newline[ s_InstLen++ ] = ';';
  736.         psz_newline[ s_InstLen ] = '\0';
  737.  
  738.         /*
  739.          * InsŠre ligne dans texte:
  740.          */
  741.         pTextLine = insert_line( pTextLine, psz_newline , NIL_1, pTextInfo );
  742.  
  743.         /*
  744.          * Mise … jour de la barre de progression: 
  745.          */
  746.         if( ul_pos+1 >= l_DoneSize + l_BlkSize )
  747.         {
  748.             /* block_size = */
  749.             update_progress( l_DoneSize ); 
  750.             
  751.             /*
  752.              * M‚morise nle position affich‚e:
  753.              */
  754.             l_DoneSize = ul_pos+1;
  755.         }
  756.     }
  757.  
  758.     /*
  759.      * Efface progress:
  760.      */
  761.     end_progress( NULL );
  762. }
  763.  
  764.  
  765.  
  766.  
  767. /*
  768.  * add_datapage(-)
  769.  *
  770.  * TEMPORAIRE
  771.  * maj statut sauvegarde
  772.  *
  773.  * Suggest:
  774.  * --------
  775.  * Impl‚menter s‚lecteur de fichier
  776.  *
  777.  * 31.08.94: fplanque: extracted from compile_page()
  778.  * 01.09.94: chgt update
  779.  * 02.09.94: prend nom par d‚faut
  780.  */
  781. DATAPAGE *    add_datapage(
  782.                     DATATYPE        DataType,        /* In: Grp de donn‚es ds lequel on cr‚e */
  783.                     const char*    psz_DefName )    /* In: Nom par d‚faut */
  784. {
  785.     DATAGROUP * pDataGroup     = find_datagroup_byType( DataType );
  786.     DATADIR     * pDataDir      = pDataGroup -> root_dir;
  787.  
  788.     /*
  789.      * Cr‚e page TEMP, ‚crase si existe d‚j…:
  790.      */
  791.     DATAPAGE     *    pDataPage = dataDir_InsertStdDataPg( psz_DefName, pDataDir );
  792.  
  793.     /*
  794.      * Mise … jour des fenˆtres et des infos de la zone de donn‚es: 
  795.      */
  796.     dataPage_chgSavState( pDataPage, SSTATE_MODIFIED, FALSE0, TRUE_1 );
  797.     /*
  798.      * R‚affiche le dir ds les fenˆtres concern‚es:
  799.      */
  800.     remplace_dir( pDataDir );
  801.     
  802.     
  803.     return    pDataPage;
  804. }
  805.  
  806.  
  807.  
  808. /*
  809.  * compile_page(-)
  810.  *
  811.  * Purpose:
  812.  * --------
  813.  * Compile le source sous forme de texte
  814.  * qui se trouve dans la top window
  815.  * en page ‚cran
  816.  *
  817.  * Suggest:
  818.  * --------
  819.  * Nom lorsque le texte n'est pas issu d'une datapage
  820.  *
  821.  * History:
  822.  * --------
  823.  * 06.07.94: fplanque: Created by extracting and renaming compile_text2vdt()
  824.  * 15.07.94: update affichage du groupe de pages
  825.  * 09.08.94: modif des routines d'update
  826.  * 02.09.94: Prend param GRECT
  827.  * 13.11.94: Utilise nom du .TXT d'origine pour nommer .VDT
  828.  */
  829. void    compile_page( GRECT * pGRect_start )    /* In: d‚but effet graphique */
  830. {
  831.     WIPARAMS    *    pWiParams = G_wi_list_adr;
  832.     char        *    pm_CompiledPage;        /* ptr sur page compil‚e en RAM */
  833.     size_t        size_CompiledPage;    /* taille du code */
  834.     char            Bsz_NomPage[ 13 ];    /* Contient nom du fichier target */
  835.  
  836.     FAKE_USE( pGRect_start );
  837.  
  838.     /* 
  839.      * V‚rifie que la fenˆtre sup‚rieure 
  840.      * contient du texte pouvant ˆtre compil‚
  841.      */
  842.     if( pWiParams == NULL || pWiParams -> type != TYP_TEXT )
  843.     {
  844.         ping();
  845.         return;
  846.     }
  847.  
  848.     /*
  849.      * D‚termine nom du fichier .VDT target:
  850.      */
  851.     if( pWiParams -> class == CLASS_DATAPAGE )
  852.     {
  853.         strcpy( Bsz_NomPage, pWiParams -> datapage -> nom );
  854.     }
  855.     else
  856.     {
  857.         strcpy( Bsz_NomPage, "TEMP" );
  858.     }
  859.     replace_extension( Bsz_NomPage, ".VDT" );
  860.  
  861.     /*
  862.      * ProcŠde … la compilation:
  863.      */
  864.     size_CompiledPage = compile_text2vdt( 
  865.                                     pWiParams -> content_ptr.textInfo, 
  866.                                     Bsz_NomPage,
  867.                                     &pm_CompiledPage );
  868.  
  869.     if( size_CompiledPage >= 0  &&  pm_CompiledPage != NULL )
  870.     {    /*
  871.          * Si la compilation est OK:
  872.           * Cr‚e datapage:
  873.          */
  874.         DATAPAGE * pDataPage = add_datapage( DTYP_PAGES, Bsz_NomPage );
  875.  
  876.         /*
  877.          * Cr‚e un datablock contenant le code la page compil‚e:
  878.          */
  879.         DATABLOCK *    pDataBlock    = create_stdDataBlock();
  880.         pDataBlock -> p_block    = pm_CompiledPage;
  881.         pDataBlock -> ul_length = size_CompiledPage;
  882.         
  883.         /*
  884.          * Assigne le code compil‚ … la nouvelle page:
  885.          */
  886.         pDataPage -> data.dataBlock = pDataBlock;
  887.     }
  888. }
  889.  
  890.  
  891. /*
  892.  * compile_text2vdt(-)
  893.  *
  894.  * Purpose:
  895.  * --------
  896.  * Compile un source sous forme de texte
  897.  * en page ‚cran
  898.  *
  899.  * Suggest:
  900.  * --------
  901.  * G‚rer pression sur ANNULER dans progress
  902.  *
  903.  * History:
  904.  * --------
  905.  * 18.06.94: fplanque: Created
  906.  * 04.07.94: permet maintenant plusieurs instructions par ligne
  907.  * 05.07.94: remodelage total: augmentation souplesse
  908.  * 06.07.94: Sauvegarde code compil‚ ds bloc m‚moire, am‚lioration gestion d'erreurs
  909.  * 06.07.94: Le code r‚cup‚rant le source ds la fenˆtre au top a ‚t‚ extrait.
  910.  * 31.07.94: Gestion des espaces et autres caractŠres sp‚ciaux … l'int‚rieur des chaines texte
  911.  * 31.07.94: Commentaires type //
  912.  * 01.08.94: Expansion des constantes symboliques
  913.  * 02.09.94: Affichage PROGRESS
  914.  * 26.09.94: Gestion des erreurs en fenetre
  915.  * 28.09.94: Fereme progress avant d'ouvrir fen d'erreurs
  916.  * 13.11.94: Prend nom de la page en param 
  917.  */
  918. size_t    compile_text2vdt(                        /* Out: Taille de la page compil‚e */
  919.                 TEXTINFO     * pTextInfo,        /* In:  Ptr sur texte source */
  920.                 const char  * cpBsz_Nom,        /* In:  Nom de la page … afficher ds progress */
  921.                 char         * * ppm_OutputBuf )    /* Out: Ptr sur buffer contenant le code compil‚ */
  922. {
  923.     /*
  924.      * Texte SOURCE:
  925.      * Saute ligne 0 et commence sur ligne no 1:
  926.      */
  927.     TEXTLINE    *    pTextLine =    pTextInfo -> firstline -> next;
  928.     char        *    pS_source;
  929.     BOOL            b_DbleQuotes;            /* ==FALSE0 si pas dans une chaine de caractŠres */
  930.     BOOL            b_AllUpper;                /* ==TRUE_1 si que des majuscules ds le param courant */ 
  931.     BOOL            b_EndParam;                /* !=FALSE0 dŠs qu'on est en fin de paramŠtre */
  932.     long            l_NbL_compiled = 0;    /* Nbre de lignes d‚j… compil‚es */
  933.  
  934.     char            cur_char;
  935.     int            n_bufLen;            /* Longueur texte dans buffer */
  936.     char        *    pS_instruction;
  937.     char        *    pS_arg1;
  938.     char        *    pS_arg2;
  939.     /*
  940.      * Gestion des erreurs:
  941.      */
  942.     int            n_status;
  943.     int            nb_errors = 0;        /* Nbre d'erreurs */
  944.     /*
  945.      * Buffer de destination de la page compil‚e:
  946.      */
  947.     size_t        size_CompBuf = pTextInfo -> nb_lignes;    /* Longueur arbitraire */
  948.     char        *    pm_CompBuf = (char *) MALLOC( size_CompBuf );    /* Buffer qui va recevoir le code compil‚ */
  949.     size_t        size_Code = 0;        /* Buffer vide */
  950.  
  951.     /*
  952.      * Affiche progress 
  953.      */
  954.     long    l_BlkSize = start_progress( 
  955.                                 " Compilation Texte -> Vid‚otex ", 
  956.                                 cpBsz_Nom, pTextInfo -> nb_lignes-1, 2, FALSE0 );
  957.     long    l_DoneSize = 0;        /* Pour l'instant on a rien compil‚ */
  958.  
  959.     /*
  960.      * Initialise buffer temporaire:
  961.      * Juste avant le d‚but, on place un ARGUMENT_SPERATOR
  962.      * ce qui sert a ne pas avoir d'effets ind‚sirables lorsque l'on teste
  963.      * le caractŠre AVANT le 1ER caractŠre!!
  964.      */
  965.     G_tmp_buffer[ 0 ] = ARGUMENT_SPERATOR;
  966.     
  967.     /*
  968.      * Texte de la ligne en cours de compilation:
  969.      */
  970.     pS_source = pTextLine -> text;
  971.  
  972.     while( pTextLine != NULL )
  973.     {    /*
  974.          * Tant qu'il y a des lignes … compiler:
  975.          *
  976.          * D‚but compilation d'une nouvelle instruction:
  977.          */
  978.         n_bufLen = 0;        /* Vide buffer */
  979.         n_status = STATUS_PROGRESS;
  980.         b_DbleQuotes    = FALSE0;
  981.         b_AllUpper        = TRUE_1;    /* A priori le prochain param est plein de majuscules */
  982.         b_EndParam        = FALSE0;
  983.  
  984.         do
  985.         {    /* --------------------------------------------------------- */
  986.  
  987.             if( pS_source == NULL )
  988.             {    /*
  989.                  * Si la ligne courante est vide:
  990.                  * Passe … la ligne suivante:
  991.                  */
  992.                 pTextLine = pTextLine -> next;
  993.                 l_NbL_compiled++;
  994.  
  995.                 if( pTextLine == NULL )
  996.                 {    /*
  997.                      * Plus de ligne suivante:
  998.                      */
  999.                     n_status = STATUS_ERR_FILEEND;
  1000.                     break;
  1001.                 }
  1002.                 /*
  1003.                  * Texte de la ligne en cours de compilation:
  1004.                  */
  1005.                 pS_source = pTextLine -> text;
  1006.  
  1007.                 continue;                
  1008.             }
  1009.             
  1010.             /*
  1011.              * Si la ligne n'est pas vide;
  1012.              */
  1013.             switch( cur_char = *( pS_source ++ ) )
  1014.             {
  1015.                 case    '\0':
  1016.                     /*
  1017.                      * Si on a trouv‚ une fin de ligne:
  1018.                      * Passe … la ligne suivante:
  1019.                      */
  1020.                     pTextLine = pTextLine -> next;
  1021.                     l_NbL_compiled++;
  1022.  
  1023.                     if( pTextLine == NULL )
  1024.                     {    /*
  1025.                          * Plus de ligne suivante:
  1026.                          */
  1027.                         n_status = STATUS_ERR_FILEEND;
  1028.                         break;
  1029.                     }
  1030.                     else
  1031.                     {    /*
  1032.                            * Texte de la nlle ligne en cours de compilation:
  1033.                           */
  1034.                         pS_source = pTextLine -> text;
  1035.                     }
  1036.  
  1037.                     if( b_DbleQuotes != FALSE0 )
  1038.                     {    /*
  1039.                          * Si on est dans du texte:
  1040.                          */
  1041.                         n_status = STATUS_ERR_LINEEND;
  1042.                         break;
  1043.                     }
  1044.                     
  1045.                     /*
  1046.                      * L'argument courant n'est pas entiŠrement constitu‚ de majuscules:
  1047.                      * c'est pas une constante:
  1048.                      */
  1049.                     b_AllUpper = FALSE0;        
  1050.  
  1051.                     break;
  1052.  
  1053.                 case    '"':
  1054.                     /*
  1055.                      * Guillemets:
  1056.                      * Fin ou d‚but de texte:
  1057.                      */
  1058.                     b_DbleQuotes = ! b_DbleQuotes;
  1059.                     /*
  1060.                      * L'argument courant n'est pas entiŠrement constitu‚ de majuscules:
  1061.                      * c'est pas une constante:
  1062.                      */
  1063.                     b_AllUpper = FALSE0;        
  1064.                     break;
  1065.  
  1066.                 case    '(':
  1067.                     /*
  1068.                      * ParenthŠse:
  1069.                      */
  1070.                     if( b_DbleQuotes == FALSE0 )
  1071.                     {    
  1072.                          b_EndParam = TRUE_1;        /* Fin d'argument atteinte */ 
  1073.                     }
  1074.                     else
  1075.                     {    /* 
  1076.                           * ParenthŠse dans un texte:
  1077.                           */
  1078.                         M_p_InstrBuf[ n_bufLen++ ] = '(';
  1079.                     }
  1080.                     break;
  1081.  
  1082.                 case    ')':
  1083.                     /*
  1084.                      * ParenthŠse:
  1085.                      */
  1086.                     if( b_DbleQuotes == FALSE0 )
  1087.                     {
  1088.                          b_EndParam = TRUE_1;        /* Fin d'argument atteinte */ 
  1089.                     }
  1090.                     else
  1091.                     {    /* 
  1092.                           * ParenthŠse dans un texte:
  1093.                           */
  1094.                         M_p_InstrBuf[ n_bufLen++ ] = ')';
  1095.                     }
  1096.                     break;
  1097.  
  1098.                 case    ',':
  1099.                     /*
  1100.                      * Virgule:
  1101.                      */
  1102.                     if( b_DbleQuotes == FALSE0 )
  1103.                     {
  1104.                          b_EndParam = TRUE_1;        /* Fin d'argument atteinte */ 
  1105.                     }
  1106.                     else
  1107.                     {    /* 
  1108.                           * Virgule dans un texte:
  1109.                           */
  1110.                         M_p_InstrBuf[ n_bufLen++ ] = ',';
  1111.                     }
  1112.                     break;
  1113.  
  1114.                 case    '/':
  1115.                     if( M_p_InstrBuf[ n_bufLen-1 ] == '/' && !b_DbleQuotes )
  1116.                     {    /*
  1117.                           * Commentaire commen‡ant par //:
  1118.                           */
  1119.                         n_bufLen --;    /* On revient sur nos pas */
  1120.                         /*
  1121.                          * On se rend … la fin de ligne, ce qui correspond … la fin d'un commentaire de type //:
  1122.                          */
  1123.                         while( *pS_source != '\0' )
  1124.                         {
  1125.                             pS_source++;
  1126.                         }
  1127.                     }
  1128.                     else
  1129.                     {    /* 
  1130.                           * Copie le caractŠre dans le buffer:
  1131.                           */
  1132.                         M_p_InstrBuf[ n_bufLen++ ] = '/';
  1133.                         /*
  1134.                          * L'argument courant n'est pas entiŠrement constitu‚ de majuscules:
  1135.                          * c'est pas une constante:
  1136.                          */
  1137.                         b_AllUpper = FALSE0;        
  1138.                     }
  1139.                     break;
  1140.  
  1141.                 case    ';':
  1142.                     /*
  1143.                      * Teste si on est dans un texte ou si c'est une fin d'instruction:
  1144.                      */
  1145.                     if( b_DbleQuotes == FALSE0 )
  1146.                     {    /*
  1147.                           * Si on a trouv‚ la fin d'une instruction:
  1148.                           */
  1149.                         n_status = STATUS_INSTRUCTOK;
  1150.                     }
  1151.                     else
  1152.                     {    /* 
  1153.                           * Point-Virgule dans un texte:
  1154.                           */
  1155.                         M_p_InstrBuf[ n_bufLen++ ] = ';';
  1156.                     }
  1157.                     break;
  1158.                     
  1159.                 default:
  1160.                     /*
  1161.                      * CaractŠre normal:
  1162.                      */
  1163.                     if( cur_char >= ' ' )
  1164.                     {    /*
  1165.                           * CaractŠre affichable:
  1166.                           */
  1167.                         if( cur_char == ' ' && b_DbleQuotes == FALSE )
  1168.                         {    /*
  1169.                              * Si on a un espace mais qu'on est pas dans un chaine:
  1170.                              * on filtre cet espace inutile:
  1171.                              */
  1172.                             break;
  1173.                         }
  1174.  
  1175.                         /*
  1176.                          * Ajoute car au buffer:
  1177.                          */
  1178.                         M_p_InstrBuf[ n_bufLen++ ] = cur_char;
  1179.  
  1180.                         if( cur_char < 'A' || cur_char > 'Z' )
  1181.                         {    /*
  1182.                              * L'argument courant n'est pas entiŠrement constitu‚ de majuscules:
  1183.                              * c'est pas une constante:
  1184.                              */
  1185.                             b_AllUpper = FALSE0;        
  1186.                         }
  1187.                     }
  1188.             }    /* Fin du switch */
  1189.  
  1190.  
  1191.  
  1192.             /*
  1193.              * Teste si on est en fin de paramŠtre:
  1194.              */
  1195.             if( b_EndParam )
  1196.             {
  1197.                 if( b_AllUpper )
  1198.                 {    /*
  1199.                      * Si le dernier param ‚tait constitu‚ uniquement de majuscules:
  1200.                      */
  1201.                     int        n_ParamStart = n_bufLen;
  1202.                     int        i;
  1203.                     char    *    psz_Constant;
  1204.                     
  1205.                     M_p_InstrBuf[ n_bufLen ] = '\0';
  1206.                     
  1207.                     /*
  1208.                      * Cherche d‚but:
  1209.                      */
  1210.                     while( M_p_InstrBuf[ --n_ParamStart ] != ARGUMENT_SPERATOR )
  1211.                     { };
  1212.                     psz_Constant = &M_p_InstrBuf[ ++n_ParamStart ];
  1213.                     
  1214.                     /* printf("\nConstante: %s<", psz_Constant ); */
  1215.  
  1216.                     /*
  1217.                      * Transforme constante en son contenu:
  1218.                      */
  1219.                     for( i = 0; i < M_nbConstantes; i++ )
  1220.                     {
  1221.                         if( strcmp( psz_Constant, M_Constantes[ i ] .psz_Var ) == 0 )
  1222.                         {    /*
  1223.                              * On a trouv‚ la constante dans la table:
  1224.                              */
  1225.                             strcpy( psz_Constant, M_Constantes[ i ] .psz_Val );
  1226.                             /*
  1227.                              * Cherche index de la fin:
  1228.                              */
  1229.                             n_bufLen = (int) (strchr( psz_Constant, '\0' ) - M_p_InstrBuf );
  1230.                         }
  1231.                     }
  1232.                 }
  1233.             
  1234.                 /*
  1235.                  * Marque la fin du param dans le buffer:
  1236.                  */
  1237.                 M_p_InstrBuf[ n_bufLen++ ] = ARGUMENT_SPERATOR;
  1238.                 b_EndParam    = FALSE0;    /* On entame un nouveau paramŠtre */
  1239.                 b_AllUpper    = TRUE_1;    /* A priori le prochain param est plein de majuscules */
  1240.             }
  1241.             
  1242.             /*                 
  1243.              * Teste conditions de fin d'instruction forc‚e:
  1244.              */
  1245.             if( n_bufLen >= INSTR_BUFFER_SIZE )
  1246.             {    /*
  1247.                  * Si on ne peut pas copier la nouvelle instruction
  1248.                  * parce qu'elle est trop longue
  1249.                  */
  1250.                 n_status = STATUS_ERR_TOOLONG;
  1251.                 break;
  1252.             }
  1253.  
  1254.  
  1255.         }    /* --------------------------------------------------------- */
  1256.         while( n_status == STATUS_PROGRESS );
  1257.  
  1258.         /*
  1259.          * ----------------------------------------------------
  1260.          * On vient de terminer l'extraction d'une instruction:
  1261.          * ----------------------------------------------------
  1262.          */
  1263.         if( n_status == STATUS_INSTRUCTOK )
  1264.         {    /*
  1265.              * Extraction OK:
  1266.              * Termine le buffer:
  1267.              */
  1268.             M_p_InstrBuf[ n_bufLen ] =    '\0';
  1269.  
  1270.             /*
  1271.              * Prend 1er token de l'instruction courante:
  1272.              */
  1273.             /*    printf( "\ninst: >%s<     ", M_p_InstrBuf ); */
  1274.             pS_instruction = strtok( M_p_InstrBuf, psz_ArgumentSeparator );
  1275.             if( pS_instruction == NULL )
  1276.             {
  1277.                 n_status = STATUS_ERR_NOTOKEN;
  1278.             }
  1279.             else
  1280.             {
  1281.                 int     n_result;
  1282.                 
  1283.                 /*
  1284.                  * Arguments (1er arg = 2Šme token):
  1285.                  */
  1286.                 pS_arg1 = strtok( NULL, psz_ArgumentSeparator );
  1287.                 pS_arg2 = strtok( NULL, psz_ArgumentSeparator );
  1288.                 
  1289.                 /*
  1290.                  * Essaie de le compiler:
  1291.                  */
  1292.                 n_result = translate_inst2code( pS_instruction, pS_arg1, pS_arg2 );
  1293.                 if( n_result < 0 )
  1294.                 {    /*
  1295.                      * S'il s'est produit une erreur:
  1296.                      */
  1297.                     n_status = n_result;
  1298.                 }
  1299.                 else
  1300.                 {    /*
  1301.                      * L'instruction a ‚t‚ correctement compil‚e:
  1302.                      */
  1303.                     
  1304.                     int    n_nbCodes = n_result;
  1305.                      
  1306.                     /* 
  1307.                      * Envoi block sur prise:
  1308.                      */
  1309.                     /* printf("\nout: %d %d", (int) G_2nd_buffer[0], (int) G_2nd_buffer[1] ); */
  1310.                     sconout( G_term_dev, n_nbCodes, G_2nd_buffer );
  1311.         
  1312.                     /*
  1313.                      * V‚rifie taille buffer de compilation:
  1314.                      */
  1315.                     if( size_Code + n_nbCodes > size_CompBuf )
  1316.                     {    /*
  1317.                          * Buffer trop petit:
  1318.                          */
  1319.                         size_CompBuf += 100;        /* Agrandi buffer */
  1320.                         pm_CompBuf = (char *) REALLOC( pm_CompBuf, size_CompBuf );
  1321.                     }
  1322.  
  1323.                     /*
  1324.                      * Sauve dans buffer de compilation:
  1325.                      */
  1326.                     memcpy( &pm_CompBuf[ size_Code ], G_2nd_buffer, n_nbCodes );
  1327.                     size_Code += n_nbCodes;
  1328.                     
  1329.                 }
  1330.             }
  1331.         }
  1332.         else if( n_status == STATUS_ERR_FILEEND && n_bufLen == 0 )
  1333.         {    /* 
  1334.              * Si on est arriv‚ … la fin du fichier, 
  1335.              * mais qu'il n'y a pas d'instruction en cours:
  1336.              */
  1337.             n_status = STATUS_INSTRUCTOK;
  1338.         }
  1339.  
  1340.         /*
  1341.          * Mise … jour de la barre de progression: 
  1342.          */
  1343.         if( l_NbL_compiled >= l_DoneSize + l_BlkSize )
  1344.         {
  1345.             /* block_size = */
  1346.             update_progress( l_DoneSize ); 
  1347.             
  1348.             /*
  1349.              * M‚morise nle position affich‚e:
  1350.              */
  1351.             l_DoneSize = l_NbL_compiled;
  1352.         }
  1353.  
  1354.  
  1355.         /*
  1356.          * Affichage message d'erreur:
  1357.          */
  1358.         if( n_status != STATUS_INSTRUCTOK )
  1359.         {    /*
  1360.              * Il y a eu une erreur:
  1361.              */
  1362.             nb_errors ++;        /* 1 de plus! */
  1363.  
  1364.             if( nb_errors == 1 )
  1365.             {    /*
  1366.                  * Si c'est la premiŠre erreur:
  1367.                  * Ferme progress et d‚bute une liste d'erreurs:
  1368.                  */
  1369.                 end_progress( NULL );
  1370.                 errorLog_AddLine( "*** Compilation Texte >> Page Ecran:" );
  1371.             }
  1372.  
  1373.             errorLog_AddLine( M_CompilerError[ n_status + 1000 ] );
  1374.         }
  1375.     }         
  1376.  
  1377.  
  1378.     /*
  1379.      * Efface progress:
  1380.      */
  1381.     end_progress( NULL );
  1382.  
  1383.  
  1384.     /*
  1385.      * Contr“le s'il y a eu des erreurs:
  1386.      */
  1387.     if( nb_errors == 0)
  1388.     {    /* 
  1389.          * Si pas d'erreur:
  1390.          */
  1391.         *ppm_OutputBuf =    pm_CompBuf;
  1392.         return                size_Code;
  1393.     }
  1394.     else
  1395.     {    /*
  1396.          * Il y a eu des erreurs:
  1397.          */
  1398.         /* text_addLineToEnd( M_pTextInfo_Errors, "Erreurs!" ); */
  1399.         
  1400.     }
  1401.  
  1402.     /*
  1403.      * Il y a eu une erreur: on abandonne la compilation.
  1404.      */
  1405.     FREE( pm_CompBuf );
  1406.     *ppm_OutputBuf =    NULL;
  1407.     return                ERROR_1;
  1408. }
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414. /*
  1415.  * translate_inst2code(-)
  1416.  *
  1417.  * Purpose:
  1418.  * --------
  1419.  * Traduit une instrction
  1420.  * en son code correspondant
  1421.  *
  1422.  * History:
  1423.  * --------
  1424.  * 18.06.94: fplanque: Created
  1425.  * 06.07.94: retourne codes d'erreurs ou nbre de codes g‚n‚r‚s
  1426.  * 31.07.94: support code(x), ink(x), loc(x,y), repeat(x), etc..
  1427.  * 01.08.94: size(), flash(), inverse(), line()
  1428.  * 03.08.94: correction bug lorsque 1stcode == NIL_1
  1429.  * 13.11.94: ttmt des cars accentu‚s ds text()
  1430.  */
  1431. int    translate_inst2code(         /* Out: nbre de codes g‚n‚r‚s ou code d'erreur si <0 */
  1432.                 char    *    pS_inst,        /* In: Instruction */
  1433.                 char    *    pS_arg1,        /* In: Premier paramŠtre */
  1434.                 char    *    pS_arg2 )    /* In: DeuxiŠme paramŠtre */
  1435. {
  1436.     int    i;
  1437.     int    n_firstCode;
  1438.     int    int1, int2;
  1439.     int    n_buf2Len = 0;
  1440.     
  1441.     for( i = 0 ; i < M_nbCodesMinitel ; i++ )
  1442.     {
  1443.         if( strcmp( pS_inst, M_TCC_minitel[ i ].pS_inst ) == 0 )
  1444.         {
  1445.             /* printf( "Inst:%s Code:%d\n", M_TCC_minitel[ i ].pS_inst, (int)M_TCC_minitel[ i ].c_1stCode ); */
  1446.  
  1447.             /*
  1448.              * M‚mo premier code:
  1449.              */
  1450.             if( (n_firstCode = M_TCC_minitel[ i ].n_1stCode) != NIL_1 )
  1451.             {
  1452.                 G_2nd_buffer[ n_buf2Len ++ ] = n_firstCode;
  1453.             }
  1454.             
  1455.             /*
  1456.              * Traite argument:
  1457.              */
  1458.             switch( M_TCC_minitel[ i ].c_procIdx )
  1459.             {
  1460.                 case    CODE_CODE:
  1461.                     /*
  1462.                      * code(x)
  1463.                      */
  1464.                     int1 = atoi( pS_arg1 );    
  1465.                     if( int1 < 0 || int1 > 255 )
  1466.                     {    
  1467.                         return STATUS_ERR_OUTOFRANGE;
  1468.                     }
  1469.                     G_2nd_buffer[ n_buf2Len ++ ] = int1;
  1470.                     break;            
  1471.  
  1472.                 case    CODE_REP:
  1473.                     /*
  1474.                      * repeat(x)
  1475.                      */
  1476.                     int1 = atoi( pS_arg1 );    
  1477.                     if( int1 < 0 || int1 > 63 )
  1478.                     {    
  1479.                         return STATUS_ERR_OUTOFRANGE;
  1480.                     }
  1481.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x40 + int1;
  1482.                     break;            
  1483.  
  1484.                 case    CODE_FLASH:
  1485.                     /*
  1486.                      * flash(ON/OFF)
  1487.                      */
  1488.                     int1 = atoi( pS_arg1 );    
  1489.                     if( int1 < 0 || int1 > 1 )
  1490.                     {    
  1491.                         return STATUS_ERR_OUTOFRANGE;
  1492.                     }
  1493.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x49 - int1;
  1494.                     break;            
  1495.  
  1496.                 case    CODE_INVERSE:
  1497.                     /*
  1498.                      * inverse(ON/OFF)
  1499.                      */
  1500.                     int1 = atoi( pS_arg1 );    
  1501.                     if( int1 < 0 || int1 > 1 )
  1502.                     {    
  1503.                         return STATUS_ERR_OUTOFRANGE;
  1504.                     }
  1505.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x5C + int1;
  1506.                     break;            
  1507.  
  1508.                 case    CODE_LINE:
  1509.                     /*
  1510.                      * line(ON/OFF)
  1511.                      */
  1512.                     int1 = atoi( pS_arg1 );    
  1513.                     if( int1 < 0 || int1 > 1 )
  1514.                     {    
  1515.                         return STATUS_ERR_OUTOFRANGE;
  1516.                     }
  1517.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x59 + int1;
  1518.                     break;            
  1519.  
  1520.                 case    CODE_SIZE:
  1521.                     /*
  1522.                      * size(NORMAL/HIGH/LARGE/DOUBLE)
  1523.                      */
  1524.                     int1 = atoi( pS_arg1 );    
  1525.                     if( int1 < 0 || int1 > 3 )
  1526.                     {    
  1527.                         return STATUS_ERR_OUTOFRANGE;
  1528.                     }
  1529.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x4C + int1;
  1530.                     break;            
  1531.  
  1532.                 case    CODE_INK:
  1533.                     /*
  1534.                      * ink(x)
  1535.                      */
  1536.                     int1 = atoi( pS_arg1 );    
  1537.                     if( int1 < 0 || int1 > 7 )
  1538.                     {    
  1539.                         return STATUS_ERR_OUTOFRANGE;
  1540.                     }
  1541.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x40 + M_CouleursVdt[ int1 ];
  1542.                     break;            
  1543.  
  1544.                 case    CODE_PAPER:
  1545.                     /*
  1546.                      * paper(x)
  1547.                      */
  1548.                     int1 = atoi( pS_arg1 );    
  1549.                     if( int1 < 0 || int1 > 7 )
  1550.                     {    
  1551.                         return STATUS_ERR_OUTOFRANGE;
  1552.                     }
  1553.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x50 + M_CouleursVdt[ int1 ];
  1554.                     break;            
  1555.  
  1556.                 case    CODE_LINE0:
  1557.                     /*
  1558.                      * line0
  1559.                      */
  1560.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x40;
  1561.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x41;
  1562.                     break;            
  1563.  
  1564.                 case    CODE_POS:
  1565.                     /*
  1566.                      * pos(y,x)
  1567.                      */
  1568.                     int1 = atoi( pS_arg1 );    
  1569.                     if( int1 < 0 || int1 > 24 )
  1570.                     {
  1571.                         return STATUS_ERR_OUTOFRANGE;
  1572.                     }
  1573.  
  1574.                     int2 = atoi( pS_arg2 );    
  1575.                     if( int2 < 1 || int2 > 40 )
  1576.                     {    
  1577.                         return STATUS_ERR_OUTOFRANGE;
  1578.                     }
  1579.  
  1580.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x40 + int1;
  1581.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x40 + int2;
  1582.                     break;            
  1583.  
  1584.                 case    CODE_LOCATE:
  1585.                     /*
  1586.                      * pos(x,y)
  1587.                      */
  1588.                     int1 = atoi( pS_arg1 );    
  1589.                     if( int1 < 1 || int1 > 40  )
  1590.                     {
  1591.                         return STATUS_ERR_OUTOFRANGE;
  1592.                     }
  1593.  
  1594.                     int2 = atoi( pS_arg2 );    
  1595.                     if( int2 < 0 || int2 > 24)
  1596.                     {    
  1597.                         return STATUS_ERR_OUTOFRANGE;
  1598.                     }
  1599.  
  1600.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x40 + int2;
  1601.                     G_2nd_buffer[ n_buf2Len ++ ] = 0x40 + int1;
  1602.                     break;            
  1603.  
  1604.                 case    CODE_TEXT:
  1605.                 {    /*
  1606.                      * text:
  1607.                      */
  1608.                     char *    pciB_CurrCar = pS_arg1;
  1609.                     char        c_CurrCar;
  1610.                     while( ( c_CurrCar = *(pciB_CurrCar++) ) != '\0' )
  1611.                     {
  1612.                         if( c_CurrCar < 128 )
  1613.                         {
  1614.                             G_2nd_buffer[ n_buf2Len ++ ] = c_CurrCar;
  1615.                         }
  1616.                         else
  1617.                         {
  1618.                             const char * cpsz_Accent = convert_Asc2Vdt( c_CurrCar );
  1619.                             strcpy( &(G_2nd_buffer[ n_buf2Len ]), cpsz_Accent );
  1620.                             n_buf2Len += (int) strlen( cpsz_Accent );
  1621.                         }
  1622.                     }
  1623.                 }
  1624.                     break;            
  1625.  
  1626.                 case    CODE_SCROLL:
  1627.                     /*
  1628.                      * scroll(ON/OFF)
  1629.                      */
  1630.                     int1 = atoi( pS_arg1 );    
  1631.                     if( int1 < 0 || int1 > 1 )
  1632.                     {    
  1633.                         return STATUS_ERR_OUTOFRANGE;
  1634.                     }
  1635.                     G_2nd_buffer[ n_buf2Len ++ ] = PRO2;
  1636.                     G_2nd_buffer[ n_buf2Len ++ ] = int1 ? P_START : P_STOP;
  1637.                     G_2nd_buffer[ n_buf2Len ++ ] = ROULEAU;
  1638.                     break;                
  1639.  
  1640.                 case    CODE_SGCHAR:
  1641.                 {    /*
  1642.                      * Macro de g‚n‚ration d'un caractŠre semi-graphique:
  1643.                      * D‚codage selon format:
  1644.                      *    positions    0 3        bits                0 1
  1645.                      *    dans            1 4        dans                2 3
  1646.                      *    source        2 5        destination        4 6
  1647.                      */
  1648.                     char    c_SgChar = 0x20;
  1649.                     
  1650.                     if( pS_arg1[ 0 ] == '*' )
  1651.                     {
  1652.                         c_SgChar |= 0x01;
  1653.                     }
  1654.  
  1655.                     if( pS_arg1[ 1 ] == '*' )
  1656.                     {
  1657.                         c_SgChar |= 0x04;
  1658.                     }
  1659.  
  1660.                     if( pS_arg1[ 2 ] == '*' )
  1661.                     {
  1662.                         c_SgChar |= 0x10;
  1663.                     }
  1664.  
  1665.                     if( pS_arg1[ 3 ] == '*' )
  1666.                     {
  1667.                         c_SgChar |= 0x02;
  1668.                     }
  1669.  
  1670.                     if( pS_arg1[ 4 ] == '*' )
  1671.                     {
  1672.                         c_SgChar |= 0x08;
  1673.                     }
  1674.  
  1675.                     if( pS_arg1[ 5 ] == '*' )
  1676.                     {
  1677.                         c_SgChar |= 0x40;
  1678.                     }
  1679.  
  1680.                     /* printf( "\n SgChar = %s -> >%c<", pS_arg1, c_SgChar ); */
  1681.                     G_2nd_buffer[ n_buf2Len ++ ] = c_SgChar;
  1682.                 }    
  1683.                     break;
  1684.             } 
  1685.  
  1686.             /*
  1687.              * Pas d'erreur:
  1688.              * Retourne le nombre de codes compil‚s:
  1689.              * (l'appellant peut les r‚cup‚rer dans G_2nd_buffer)
  1690.              */
  1691.             return    n_buf2Len;
  1692.         }
  1693.     }
  1694.  
  1695.     /*
  1696.      * L'instruction n'est pas reconnue:
  1697.      */
  1698.     return    STATUS_ERR_UNKNOWN;
  1699. }
  1700.  
  1701.  
  1702. /*
  1703.  * watch_PageEcran(-)
  1704.  *
  1705.  * Purpose:
  1706.  * --------
  1707.  * Selection d'une page ‚cran puis visualisation
  1708.  *
  1709.  * History:
  1710.  * --------
  1711.  * 08.01.95: fplanque: Created
  1712.  */
  1713. void    watch_PageEcran(
  1714.             OBJECT    *    pObj_CallForm,    /* In: Formulaire appellant */
  1715.             int             call_obj )        /* In: objet appellant */
  1716. {
  1717.     /* Datagroup dans lequel on va choisir une page */
  1718.     DATAGROUP *    pDataGroup = find_datagroup_byType( DTYP_PAGES );
  1719.     /* Va recevoir s‚lection */
  1720.     char         *    piBsz_PageName = NULL;
  1721.     /* Adr de la page trouv‚e */
  1722.     DATAPAGE     *    pDataPage_Ecran;
  1723.  
  1724.     /*
  1725.      * S‚lecteur RAM: 
  1726.      */
  1727.     RAMSEL selection = ramselect_fromForm( "Voir une Page Ecran:",
  1728.                                                  pDataGroup, &piBsz_PageName,
  1729.                                                  pObj_CallForm, call_obj );
  1730.  
  1731.     if( selection != RAMSEL_ABORT )
  1732.     {
  1733.         /*
  1734.          * Cherche page demand‚e: 
  1735.          */
  1736.         pDataPage_Ecran = page_adr_bynamecmp( pDataGroup -> root_dir, &piBsz_PageName[5] );
  1737.  
  1738.         if( pDataPage_Ecran == NULL )
  1739.         {    /*
  1740.              * On a pas trouv‚ la page ‚cran: 
  1741.              */
  1742.             alert( ENOENT );
  1743.             return;
  1744.         }
  1745.  
  1746.         /*
  1747.          * Visu de la page:
  1748.          */
  1749.         visu_page( pDataPage_Ecran, pObj_CallForm );     /* Visu page */
  1750.  
  1751.     }
  1752.  
  1753. }
  1754.  
  1755. /*
  1756.  * visu_page(-)
  1757.  *
  1758.  * Purpose:
  1759.  * --------
  1760.  * Visu d'une page ‚cran sur le terminal
  1761.  *
  1762.  * History:
  1763.  * --------
  1764.  * 1993: fplanque: Created
  1765.  * 08.01.95: gŠre arbre appellant
  1766.  */
  1767. void    visu_page( 
  1768.             DATAPAGE    *    pDataPage,            /* In: Page ‚cran … afficher */ 
  1769.             OBJECT    *    pObj_CallForm )    /* In: Arbre appellant, peut ˆtre NULL */
  1770. {
  1771.     DATABLOCK * pDatablock = pDataPage -> data.dataBlock;
  1772.     long            block_size;            /* Taille des blocs entre 2 mises … jour du progress: */
  1773.     char        *    page_ptr;            /* Pointeur dans la page */
  1774.     long            done_size = 0;
  1775.  
  1776.     /*
  1777.      * Affiche progress 
  1778.      */
  1779.     block_size = start_progress( " Visu page sur terminal: ", pDataPage -> nom, pDatablock -> ul_length, 30, (pObj_CallForm != NULL) );
  1780.     
  1781.     /*
  1782.      * Envoi de la page au minitel: 
  1783.      */
  1784.     page_ptr = pDatablock -> p_block;        /* Ptr sur d‚but de la page */
  1785.  
  1786.     while( done_size < pDatablock -> ul_length )
  1787.     {
  1788.         /*
  1789.          * Envoi d'un block: 
  1790.          */
  1791.         sconout ( G_term_dev, block_size, page_ptr );
  1792.  
  1793.         /*
  1794.          * On se place au d‚but du bloc suivant: 
  1795.          */
  1796.         done_size += block_size;            /* Taille d‚j… envoy‚e */
  1797.         page_ptr += block_size;                /* Passe … la suite */
  1798.  
  1799.         /*
  1800.          * Mise … jour de la barre de progression: 
  1801.          * et recup‚ration taille prochain block
  1802.          */
  1803.         block_size = update_progress( done_size ); 
  1804.         
  1805.         /*
  1806.          * Contr“le si on a pas annul‚: 
  1807.          */
  1808.         if( block_size < 0 )
  1809.         {    /*
  1810.              * Si on a annul‚: 
  1811.              */
  1812.             break;
  1813.         }
  1814.         
  1815.     }
  1816.  
  1817.     /*
  1818.      * Efface progress:
  1819.      */
  1820.     end_progress( pObj_CallForm );
  1821. }
  1822.